package com.appprogram.baseapppackage.ui.main;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.CountDownTimer;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.appprogram.baseapppackage.MainActivity;
import com.appprogram.baseapppackage.R;
import com.appprogram.baseapppackage.databinding.WelcomeActivityBinding;
import com.appprogram.baseapppackage.notchtools.NotchTools;
import com.appprogram.baseapppackage.notchtools.core.NotchProperty;
import com.appprogram.baseapppackage.notchtools.core.OnNotchCallBack;

/**
 * BaseAppPackage com.appprogram.baseapppackage.ui.main
 * 2020-01-08 09:29
 */
public class WelcomeActivity extends AppCompatActivity {
    private long millisInFuture = 4000;
    private long countDownInterval = 1000;
    private WelcomeActivityBinding mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        //适配全面屏、刘海屏
        NotchTools.getFullScreenTools().fullScreenDontUseStatus(this);
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.welcome_activity);
        initData();
    }

    private void initData() {
        Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/STKAITI.TTF");
        mBinding.tvTitle.setTypeface(fontFace);

        mBinding.simpleIv.setImageResource(R.drawable.ic_launcher_web);
        //倒计时
        CountDownTimer countDownTimer = new CountDownTimer(millisInFuture, countDownInterval) {
            @Override
            public void onTick(long millisUntilFinished) {
                String time = millisUntilFinished / 1000 + "";
                mBinding.tvSkip.setText(time);
            }

            @Override
            public void onFinish() {
                jumpActivity();
            }
        };
        countDownTimer.start();

        //跳过按钮
        mBinding.tvSkip.setOnClickListener(v -> {
            countDownTimer.cancel();
            jumpActivity();
        });
    }

    private void jumpActivity() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
